package com.yc.Testjvm.invoke;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class MethodHandleTest4 {
	
	public MethodHandle getHandler() {
		MethodHandle mh = null;
		MethodType mt = MethodType.methodType(void.class);
		try {
			mh=MethodHandles.lookup().findVirtual(MethodHandleTest4.class, "print", mt);
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		
		return mh;
	}
	
	public void print() {
		System.out.println("print");
	}

	public static void main(String[] args) throws Throwable {
		MethodHandleTest4 mht = new MethodHandleTest4();
		MethodHandle mh = mht.getHandler();
		
		int result1 = (int) mh.invoke(mht);
		Object result2 = mh.invoke(mht);
		
		System.out.println("result1: " + result1);
		System.out.println("result2: " + result2);
	}

}
